<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<#include "../commons/imports.html"/>
</head>
<body class="layui-layout-body">

	<div class="layui-layout layui-layout-admin">
		<#include "../commons/header.html"/> <#include
		"../commons/sider.html"/>
		<div class="layui-body">
			<blockquote class="layui-elem-quote">
				<div class="layui-inline">
					<div class="layui-input-inline">
						<input type="text" value="" placeholder="请输入用户姓名"
							class="layui-input search_input layui-btn-disabled">
					</div>
					<a class="layui-btn search_btn layui-btn-disabled">
					<i class="layui-icon">&#xe615;</i>查询</a>
				</div>
				<div class="layui-inline">
					<div class="layui-btn-group">
						<button class="layui-btn layui-btn-sm" onclick="editUser()">
							<i class="layui-icon"></i>增加
						</button>
					</div>
				</div>
			</blockquote>
			<div style="padding: 5px;">
				<table class="layui-table">
					<colgroup>
						<col width="100">
						<col width="100">
						<col width="200">
						<col width="100">
						<col width="300">
						<col width="300">
					</colgroup>
					<thead>
						<tr>
							<th>账号</th>
							<th>姓名</th>
							<th>创建时间</th>
							<th>状态</th>
							<th>角色列表</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<#list users as user>
						<tr>
							<td>${user.account!}</td>
							<td>${user.userName!}</td>
							<td>${user.createTime?string("yyyy-MM-dd HH:mm:ss")}</td>
							<td>${(user.status==1)?string('正常','锁定')}</td>
							<td>${user.roleCodes!}</td>
							<td>
							<#if user.status==1>
							<a class="layui-btn layui-btn-mini" onclick="lock('${user.account}')">
								<i class="layui-icon">&#xe631;</i> 锁定</a>
							</#if>	
							<#if user.status==2>
							<a class="layui-btn layui-btn-mini" onclick="unlock('${user.account}')">
								<i class="layui-icon">&#xe631;</i> 解锁</a>
							</#if>	
							<a class="layui-btn layui-btn-mini" onclick="editUser('${user.account}')">
								<i class="layui-icon">&#xe642;</i> 编辑</a>
							</td>
						</tr>
						</#list>
					</tbody>
				</table>
			</div>

			<!-- 内容主体区域 -->

		</div>
		<#include "../commons/footer.html"/>
	</div>
	<script type="text/javascript" src="${ctx}/assets/js/main.js"></script>
	<script>
		function editUser(_account) {
			ajaxPost("${ctx}/user/edit",{
				account:_account
			},function(result) {
				layer.open({
					type:1,
					title : '编辑用户',
					area : [ '700px', '450px' ],
					skin : 'layui-layer-lan',
					btn : '关闭',
					content : result
				});
			});
		}
		function saveUser() {
			var _roleNames = [];
			$("#save-user-form option:selected").each(function(){
				_roleNames.push($(this).val());
	        });
			var formData = formToJson('save-user-form');
			formData.roleCodes = _roleNames.join(',');
			if (formData.account=='') {
				layer.alert('账号不能为空',{icon:2, title:'错误'});
				return;
			} 
			if (formData.password=='') {
				layer.alert('密码不能为空',{icon:2, title:'错误'});
				return;
			} 
			if (formData.userName=='') {
				layer.alert('姓名不能为空',{icon:2, title:'错误'});
				return;
			} 
			ajaxJson("${ctx}/user/save",JSON.stringify(formData),function(result) {
				layer.closeAll();
				layer.alert('用户添加成功',{icon:1, title:'成功'});
				window.location.href = '${ctx}/user/list';
			});
		}
		function lock(_account) {
			ajaxPost("${ctx}/user/switch_lock",{
				 account:_account
				,lockStatus:2
			},function(result) {
				window.location.href = '${ctx}/user/list';
				layer.alert('用户锁定成功',{icon:1, title:'成功'});
			});
		}
		function unlock(_account) {
			ajaxPost("${ctx}/user/switch_lock",{
				 account:_account
				,lockStatus:1
			},function(result) {
				window.location.href = '${ctx}/user/list';
				layer.alert('用户解锁成功',{icon:1, title:'成功'});
			});
		}
	</script>
</body>
</html>